<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Amodule extends Model
{
    public $table = 'amodule';

    public $primaryKey = 'id';

    public $timestamps = false;
    // public $guard = [];
     public $guarded = [];

    //数据格式化
    public function tree()
    {
    	$cates = $this->orderBy('order','asc')->get();
    	return $this->getTree($cates,0);
    }

    public function getTree($cates,$pic=0)
    {
    	$arr = [];
    	foreach($cates as $k => $v){
    		if($v->pic == $pic){
    			$v['aname'] = $v['mname'];
    			$arr[] = $v;

    			foreach($cates as $m => $n){
    				if($n->pic == $v->id){
    					$n['aname'] = '|------'.$n['mname'];
    					$arr[] = $n;

    				}
    			}
    		}
    	}

        return $arr;
    }


}
